﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProjectEdificio
{
    class Authentication
    {

        private BDManagment bdm = null;
        private Dictionary<String, Usuario> users = null;
        private Usuario userON = null;
        private static Authentication auti = null;

        private Authentication()
        {
            bdm = BDManagment.getInstance();
            users = bdm.getListUsers();
        }

        public static Authentication getInstance()
        {
            if (auti == null)
            {
                auti = new Authentication();
            }
                return auti;
        }

        public bool setUser(string us, string pas)
        {
            if (users.ContainsKey(us))
            {
                userON = users[us];
                if (pas == userON.Pass)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        public Usuario getUser()
        {
            return userON;
        }

        public void closedSession()
        {
            this.userON = null;
        }

    }
}
